/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Busqueda.java
 *
 * Created on 23-dic-2011, 21:51:13
 */
package GUI_SPR;

import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import persistence.UsoPersisteceMySQLConnection;
import sourceCode.Cuenta;

/**
 *
 * @author edwin
 */
public class Busqueda extends javax.swing.JFrame {

    /** Creates new form Busqueda */
    public Busqueda() {
        initComponents();
        try {
            this.jLabel3.setText(cuenta.getUsuario());
        }
        catch(Exception e) {
            JOptionPane.showMessageDialog(null, e);
        }
        this.pack();
    }
    
    
        public static void setCuenta(String usuarioX, String contrasenaC){
        cuenta.setUsuario(usuarioX);
        cuenta.setContraseñaMaestra(contrasenaC);
    }
    public static void setCuenta(Cuenta cuentaX){
        cuenta = cuentaX;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jP_BusquedaTablas = new JPanel();
        jTF_BT_Busqueda = new JTextField();
        jB_BT_Buscar = new javax.swing.JButton();
        jL_BT_NombreGrupo = new JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jT_BusquedaTablas = new javax.swing.JTable();
        categoriaCBox = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        categoriaCBox1 = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        backmenuB = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jP_BusquedaTablas.setBackground(new java.awt.Color(204, 204, 255));
        jP_BusquedaTablas.setBorder(javax.swing.BorderFactory.createTitledBorder("busqueda"));
        jP_BusquedaTablas.setPreferredSize(new java.awt.Dimension(500, 508));

        jB_BT_Buscar.setText("Buscar");
        jB_BT_Buscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jB_BT_BuscarActionPerformed(evt);
            }
        });

        jL_BT_NombreGrupo.setFont(new java.awt.Font("Tempus Sans ITC", 1, 18));
        jL_BT_NombreGrupo.setText("Busqueda");

        jScrollPane2.setViewportView(jT_BusquedaTablas);

        categoriaCBox.setFont(new java.awt.Font("Bookman Old Style", 0, 11));
        categoriaCBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "", "Producto de Tienda", "Producto de Libreria", "Productos varios", "Proveedores", "Marcas" }));
        categoriaCBox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                categoriaCBoxItemStateChanged(evt);
            }
        });
        categoriaCBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                categoriaCBoxActionPerformed(evt);
            }
        });

        jLabel1.setText("En:");

        jLabel2.setText("Usuario");

        jLabel3.setText("-------");

        categoriaCBox1.setFont(new java.awt.Font("Bookman Old Style", 0, 11));
        categoriaCBox1.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                categoriaCBox1ItemStateChanged(evt);
            }
        });
        categoriaCBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                categoriaCBox1ActionPerformed(evt);
            }
        });

        jLabel4.setText("Categoria:");

        javax.swing.GroupLayout jP_BusquedaTablasLayout = new javax.swing.GroupLayout(jP_BusquedaTablas);
        jP_BusquedaTablas.setLayout(jP_BusquedaTablasLayout);
        jP_BusquedaTablasLayout.setHorizontalGroup(
            jP_BusquedaTablasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jP_BusquedaTablasLayout.createSequentialGroup()
                .addGap(254, 254, 254)
                .addComponent(jL_BT_NombreGrupo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 286, Short.MAX_VALUE)
                .addComponent(jLabel2)
                .addGap(18, 18, 18)
                .addComponent(jLabel3)
                .addGap(82, 82, 82))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jP_BusquedaTablasLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jP_BusquedaTablasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 762, Short.MAX_VALUE)
                    .addGroup(jP_BusquedaTablasLayout.createSequentialGroup()
                        .addComponent(jTF_BT_Busqueda, javax.swing.GroupLayout.PREFERRED_SIZE, 263, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(68, 68, 68)
                        .addComponent(jB_BT_Buscar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 64, Short.MAX_VALUE)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(categoriaCBox, javax.swing.GroupLayout.PREFERRED_SIZE, 276, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jP_BusquedaTablasLayout.createSequentialGroup()
                .addContainerGap(435, Short.MAX_VALUE)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(categoriaCBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 276, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jP_BusquedaTablasLayout.setVerticalGroup(
            jP_BusquedaTablasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jP_BusquedaTablasLayout.createSequentialGroup()
                .addGroup(jP_BusquedaTablasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jL_BT_NombreGrupo)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jP_BusquedaTablasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTF_BT_Busqueda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jB_BT_Buscar)
                    .addComponent(categoriaCBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jP_BusquedaTablasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(categoriaCBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(15, 15, 15)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 367, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        backmenuB.setFont(new java.awt.Font("Bookman Old Style", 0, 11));
        backmenuB.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/icon/home.png"))); // NOI18N
        backmenuB.setText("Menu");
        backmenuB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backmenuBActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(26, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jP_BusquedaTablas, javax.swing.GroupLayout.PREFERRED_SIZE, 794, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(backmenuB))
                .addGap(30, 30, 30))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(52, Short.MAX_VALUE)
                .addComponent(jP_BusquedaTablas, javax.swing.GroupLayout.PREFERRED_SIZE, 501, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(backmenuB)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jB_BT_BuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jB_BT_BuscarActionPerformed
        String tableX = jL_BT_NombreGrupo.getText();
        String txtBuscar = jTF_BT_Busqueda.getText();
            repaint();
        if (String.valueOf(this.categoriaCBox.getSelectedItem()).equals("Producto de Tienda") && String.valueOf(this.categoriaCBox1.getSelectedItem()).equals("bebidas")){
          UsoPersisteceMySQLConnection.cargarTablaBebidas(jT_BusquedaTablas,txtBuscar);
        }
        else {
        if (String.valueOf(this.categoriaCBox.getSelectedItem()).equals("Producto de Tienda") && String.valueOf(this.categoriaCBox1.getSelectedItem()).equals("otros")){
            UsoPersisteceMySQLConnection.cargarTablaTienda(jT_BusquedaTablas, txtBuscar);
        }
        else {
        if (String.valueOf(this.categoriaCBox.getSelectedItem()).equals("Producto de Libreria")){
            UsoPersisteceMySQLConnection.cargarTablaLibreria(jT_BusquedaTablas,txtBuscar);
        }
            else {
            if (String.valueOf(this.categoriaCBox.getSelectedItem()).equals("Productos varios")){
         UsoPersisteceMySQLConnection.cargarTablaVarios(jT_BusquedaTablas,txtBuscar);
            }
            else{
            if (String.valueOf(this.categoriaCBox.getSelectedItem()).equals("Proveedores")){
         UsoPersisteceMySQLConnection.cargarTablaProveedores(jT_BusquedaTablas,txtBuscar);
            }
            else {
            if (String.valueOf(this.categoriaCBox.getSelectedItem()).equals("Marcas")){
                         UsoPersisteceMySQLConnection.cargarTablaMarcas(jT_BusquedaTablas,txtBuscar);

            }
            else {
                JOptionPane.showMessageDialog(null, "Escoja una categoría!! para realizar la busquda");
            }        
            }
            }
            }
        }
            }
    }//GEN-LAST:event_jB_BT_BuscarActionPerformed

    private void backmenuBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backmenuBActionPerformed
        jTF_BT_Busqueda.setText("");
        MenuOpciones menu = new MenuOpciones ();
        menu.show();
        dispose();
    }//GEN-LAST:event_backmenuBActionPerformed

    private void categoriaCBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_categoriaCBoxItemStateChanged
/*
        setModels(UsoPersisteceMySQLConnection.encontrarNombresMarcas(), UsoPersisteceMySQLConnection.encontrarNombresProveedor());                  ocultarPanels();         //Determina si está seleccionado en el combo box la opción de aplicación de internet y realiza lo necesario.         if (String.valueOf(this.categoriaCBox.getSelectedItem()).equals("Producto de Tienda")) {             ProductoJP.setVisible(true);             ID_p.setText("" + (1 + Integer.parseInt(UsoPersisteceMySQLConnection.getCantidadDatos("productos_tienda"))));         } else {             if (String.valueOf(this.categoriaCBox.getSelectedItem()).equals("Producto de Libreria")) {                 ProductoJP.setVisible(true);                 ID_p.setText("" + (1 + Integer.parseInt(UsoPersisteceMySQLConnection.getCantidadDatos("productos_libreria"))));             } else {                 if (String.valueOf(this.categoriaCBox.getSelectedItem()).equals("Productos varios")) {                     ProductoJP.setVisible(true);                     ID_p.setText("" + (1 + Integer.parseInt(UsoPersisteceMySQLConnection.getCantidadDatos("productos_varios"))));                 } else {                     if (String.valueOf(this.categoriaCBox.getSelectedItem()).equals("Proveedores")) {                         ProveedorJP.setVisible(true);                         ID_p2.setText("" + (1 + Integer.parseInt(UsoPersisteceMySQLConnection.getCantidadDatos("proveedores"))));                     } else {                         if (String.valueOf(this.categoriaCBox.getSelectedItem()).equals("Marcas")) {                             MarcaJP.setVisible(true);                             ID_p1.setText("" + (1 + Integer.parseInt(UsoPersisteceMySQLConnection.getCantidadDatos("marcas"))));                         } else {                             ocultarPanels();                         }                                             }                 }             }         }     }//GEN-LAST:event_categoriaCBoxItemStateChanged
  */ 
        categoriaCBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "","bebidas", "otros"}));

    
    
    }
        private void categoriaCBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_categoriaCBoxActionPerformed

    }//GEN-LAST:event_categoriaCBoxActionPerformed

    private void categoriaCBox1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_categoriaCBox1ItemStateChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_categoriaCBox1ItemStateChanged

    private void categoriaCBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_categoriaCBox1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_categoriaCBox1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Busqueda.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Busqueda.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Busqueda.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Busqueda.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Busqueda().setVisible(true);
            }
        });
    }
    private static Cuenta cuenta;
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton backmenuB;
    private javax.swing.JComboBox categoriaCBox;
    private javax.swing.JComboBox categoriaCBox1;
    private javax.swing.JButton jB_BT_Buscar;
    private javax.swing.JLabel jL_BT_NombreGrupo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    public javax.swing.JPanel jP_BusquedaTablas;
    private javax.swing.JScrollPane jScrollPane2;
    public javax.swing.JTextField jTF_BT_Busqueda;
    public javax.swing.JTable jT_BusquedaTablas;
    // End of variables declaration//GEN-END:variables
}
